//关于“产品中心”的产品详情


//一、关于前期准备


const express = require('express');
const router = express.Router();//路由器
const ProDetailControllers=require('../controllers/proDetailController.js');

const path=require('path');
//完成上传文件功能——>npm install --save multer——>引入
const multer  = require('multer');

//3.获取文件信息
//3.1
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, path.join(__dirname,'../public/uploads/'));
    },
    filename: function (req, file, cb) {
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
        //获取文件的名字（包含扩展名）
        cb(null, file.fieldname + '-' + uniqueSuffix+path.extname(file.originalname))
    }
});
//3.2
const upload = multer({ storage: storage });

//二、关于功能实现

//1.“产品分类”curd
//1.1.“产品中心分类”添加
//1.1.1添加页面渲染
router.get('/proCenter/add',ProDetailControllers.getProCenterAdd);
//1.1.2增加表单提交后
router.post('/proCenter/store',ProDetailControllers.getProCenterStore);

//1.2.“产品分类”展示
router.get('/proCenter/list',ProDetailControllers.getProCenterList);

//1.3.“产品分类”删除
router.get('/proCenter/delete/:id',ProDetailControllers.getProCenterDelete);

//1.4.“产品分类”编辑
//1.4.1通过id进行查找到当前内容
router.get('/proCenter/edit/:id',ProDetailControllers.getProCenterEdit);
//1.4.2表单提交后通过id进行查找内容，修改当前内容的信息，保存至数据库
router.post('/proCenter/editStore',ProDetailControllers.getProCenterEditStore);

//2.“产品详情”curd和首页
//2.1“产品详情”添加
//2.1.1添加页面渲染
router.get('/proDetail/add',ProDetailControllers.getProDetailAdd);
//2.1.2增加表单提交后
router.post('/proDetail/store',upload.single('pic'),ProDetailControllers.getProDetailStore);

//2.2.“产品详情”展示
router.get('/proDetail/list',ProDetailControllers.getProDetailList);

//2.3“产品详情”删除
router.get('/proDetail/delete/:id',ProDetailControllers.getProDetailDelete);

//2.4“产品详情”编辑
//2.4.1通过id进行查找到当前内容
router.get('/proDetail/edit/:id',ProDetailControllers.getProDetailEdit);
//2.4.2表单提交后通过id进行查找内容，修改当前内容的信息，保存至数据库
router.post('/proDetail/editStore',upload.single('pic'),ProDetailControllers.getProDetailEditStore);

//3.前台页面的展示
//3.1这是“产品详情”首页
router.get('/view-48', ProDetailControllers.getProFrontList);


//三、暴露

//暴露出去
module.exports = router;